<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>硬布线控制实验（Ⅱ） :: 计算机组成原理实验指导</title>
    <meta name="generator" content="Antora 3.2.0-alpha.8">
    <link rel="stylesheet" href="../../../_/css/site.css">
<!--    <script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"></script> -->
  </head>
  <body class="article">
<header class="header">
  <nav class="navbar">
    <div class="navbar-brand">
      <a class="navbar-item" href="../../..">计算机组成原理实验指导</a>
      <button class="navbar-burger" aria-controls="topbar-nav" aria-expanded="false" aria-label="Toggle main menu">
        <span></span>
        <span></span>
        <span></span>
      </button>
    </div>
    <div id="topbar-nav" class="navbar-menu">
      <div class="navbar-end">

        <div class="navbar-item">
          <span class="control">
            <a class="button is-primary" href="https://gitee.com/fpga-lab/digisimlab-open" target="_blank">Download</a>
          </span>
        </div>
      </div>
    </div>
  </nav>
</header>
<div class="body">
<div class="nav-container" data-component="digisimlab" data-version="1.0">
  <aside class="nav">
    <div class="panels">
<div class="nav-panel-menu is-active" data-panel="menu">
  <nav class="nav-menu">
    <button class="nav-menu-toggle" aria-label="Toggle expand/collapse all" style="display: none"></button>
    <h3 class="title"><a href="../index.html">计算机组成原理实验指导</a></h3>
<ul class="nav-list">
  <li class="nav-item" data-depth="0">
<ul class="nav-list">
  <li class="nav-item" data-depth="1">
    <a class="nav-link" href="../index.html">前言</a>
  </li>
</ul>
  </li>
  <li class="nav-item" data-depth="0">
    <button class="nav-item-toggle"></button>
    <span class="nav-text">Digital仿真软件使用指南</span>
<ul class="nav-list">
  <li class="nav-item" data-depth="1">
    <a class="nav-link" href="../introduce-digitalsim.html">下载与安装</a>
  </li>
  <li class="nav-item" data-depth="1">
    <a class="nav-link" href="../ds-getting-started.html">新手入门</a>
  </li>
  <li class="nav-item" data-depth="1">
    <a class="nav-link" href="../ds-generate-circuit.html">电路生成</a>
  </li>
  <li class="nav-item" data-depth="1">
    <a class="nav-link" href="../ds-test-circuit.html">电路测试</a>
  </li>
  <li class="nav-item" data-depth="1">
    <a class="nav-link" href="../ds-sim-dff.html">时序电路仿真</a>
  </li>
  <li class="nav-item" data-depth="1">
    <a class="nav-link" href="../ds-other-useful.html">几个有用的组件</a>
  </li>
  <li class="nav-item" data-depth="1">
    <a class="nav-link" href="../ds-hierarchical-design.html">层次化设计</a>
  </li>
  <li class="nav-item" data-depth="1">
    <a class="nav-link" href="../ds-parametric-design.html">参数化设计</a>
  </li>
</ul>
  </li>
  <li class="nav-item" data-depth="0">
<ul class="nav-list">
  <li class="nav-item" data-depth="1">
    <button class="nav-item-toggle"></button>
    <span class="nav-text">基本逻辑电路</span>
<ul class="nav-list">
  <li class="nav-item" data-depth="2">
    <a class="nav-link" href="bl-overview.html">概述</a>
  </li>
  <li class="nav-item" data-depth="2">
    <a class="nav-link" href="bl-multiplexer.html">多路选择器实验</a>
  </li>
  <li class="nav-item" data-depth="2">
    <a class="nav-link" href="bl-decoder.html">译码器实验</a>
  </li>
  <li class="nav-item" data-depth="2">
    <a class="nav-link" href="bl-counter.html">计数器实验</a>
  </li>
</ul>
  </li>
  <li class="nav-item" data-depth="1">
    <button class="nav-item-toggle"></button>
    <span class="nav-text">运算电路</span>
<ul class="nav-list">
  <li class="nav-item" data-depth="2">
    <a class="nav-link" href="op-add_sub_operation.html">加减运算电路实验</a>
  </li>
  <li class="nav-item" data-depth="2">
    <a class="nav-link" href="op-arithmetic_logic_unit.html">算术逻辑单元实验</a>
  </li>
  <li class="nav-item" data-depth="2">
    <a class="nav-link" href="op-compare.html">比较运算电路实验</a>
  </li>
</ul>
  </li>
  <li class="nav-item" data-depth="1">
    <button class="nav-item-toggle"></button>
    <span class="nav-text">数据通路</span>
<ul class="nav-list">
  <li class="nav-item" data-depth="2">
    <a class="nav-link" href="dp-overview.html">概述</a>
  </li>
  <li class="nav-item" data-depth="2">
    <a class="nav-link" href="dp-register_file.html">寄存器堆实验</a>
  </li>
  <li class="nav-item" data-depth="2">
    <a class="nav-link" href="dp-single_cycle_datapath.html">单周期数据通路实验</a>
  </li>
</ul>
  </li>
  <li class="nav-item" data-depth="1">
    <button class="nav-item-toggle"></button>
    <span class="nav-text">存储器</span>
<ul class="nav-list">
  <li class="nav-item" data-depth="2">
    <a class="nav-link" href="mem-memory.html">存储器实验</a>
  </li>
</ul>
  </li>
  <li class="nav-item" data-depth="1">
    <button class="nav-item-toggle"></button>
    <span class="nav-text">控制器</span>
<ul class="nav-list">
  <li class="nav-item" data-depth="2">
    <a class="nav-link" href="cu-overview.html">概述</a>
  </li>
  <li class="nav-item" data-depth="2">
    <a class="nav-link" href="cu-hardwire_controller-1.html">硬布线控制实验（Ⅰ）</a>
  </li>
  <li class="nav-item is-current-page" data-depth="2">
    <a class="nav-link" href="cu-hardwire_controller.html">硬布线控制实验（Ⅱ）</a>
  </li>
  <li class="nav-item" data-depth="2">
    <a class="nav-link" href="cu-hardwire_controller-3.html">硬布线控制实验（Ⅲ）</a>
  </li>
</ul>
  </li>
</ul>
  </li>
</ul>
  </nav>
</div>
<div class="nav-panel-explore" data-panel="explore">
  <div class="context">
    <span class="title">计算机组成原理实验指导</span>
    <span class="version">1.0</span>
  </div>
  <ul class="components">
    <li class="component is-current">
      <div class="title"><a href="../../index.html">计算机组成原理实验指导</a></div>
      <ul class="versions">
        <li class="version is-latest">
          <a href="../../index.html">1.31</a>
        </li>
        <li class="version">
          <a href="../../1.2/index.html">1.2</a>
        </li>
        <li class="version">
          <a href="../../1.1/index.html">1.1</a>
        </li>
        <li class="version is-current">
          <a href="../index.html">1.0</a>
        </li>
      </ul>
    </li>
  </ul>
</div>
    </div>
  </aside>
</div>
<main class="article">
<div class="toolbar" role="navigation">
<button class="nav-toggle"></button>
  <a href="../../index.html" class="home-link"></a>
<nav class="breadcrumbs" aria-label="breadcrumbs">
  <ul>
    <li><a href="../index.html">计算机组成原理实验指导</a></li>
    <li>控制器</li>
    <li><a href="cu-hardwire_controller.html">硬布线控制实验（Ⅱ）</a></li>
  </ul>
</nav>
<div class="page-versions">
  <button class="version-menu-toggle" title="Show other versions of page">1.0</button>
  <div class="version-menu">
    <a class="version" href="../../lab/cu-hardwire_controller.html">1.31</a>
    <a class="version" href="../../1.2/lab/cu-hardwire_controller.html">1.2</a>
    <a class="version" href="../../1.1/lab/cu-hardwire_controller.html">1.1</a>
    <a class="version is-current" href="cu-hardwire_controller.html">1.0</a>
  </div>
</div>
</div>
  <div class="content">
<aside class="toc sidebar" data-title="页内目录" data-levels="2">
  <div class="toc-menu"></div>
</aside>
<article class="doc">
<h1 class="page">硬布线控制实验（Ⅱ）</h1>
<div class="sect1">
<h2 id="_实验目的"><a class="anchor" href="#_实验目的"></a>实验目的</h2>
<div class="sectionbody">
<div class="olist arabic">
<ol class="arabic">
<li>
<p>理解Ｉ型和R型整数运算指令以及B型分支指令的功能。</p>
</li>
<li>
<p>理解单周期数据通路的组成结构及其信息加工过程。</p>
</li>
<li>
<p>掌握单周期硬布线控制信号的产生原理和设计方法。</p>
</li>
</ol>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_实验原理"><a class="anchor" href="#_实验原理"></a>实验原理</h2>
<div class="sectionbody">
<div class="paragraph">
<p>在前面<a href="dp-single_cycle_datapath.html" class="xref page">数据通路实验</a>的基础上，增加指令存储器、控制器等部件，可以看成是一个简单的计算机主机。原理框图如<a href="#fig-cu-arch-2">图 1</a>。</p>
</div>
<div id="fig-cu-arch-2" class="imageblock">
<div class="content">
<img src="_images/cu-arch-2.png" alt="cu arch 2">
</div>
<div class="title">图 1. 支持分支指令的单周期数据通路及控制</div>
</div>
<div class="sect2">
<h3 id="_指令部件"><a class="anchor" href="#_指令部件"></a>指令部件</h3>
<div class="paragraph">
<p>指令部件包括指令存储器和程序计数器。根据指令系统的设计，指令存储器的字长是14位。作为实验计算机，只需要存放简单的程序，所以指令存储器的容量只有16个存储单元，可以存放16条指令。因此指令存储器的地址需4位，由程序计数器PC提供。复位时PC值为0，即第一条指令的地址。在Clk上升沿到来时，如果Load为1，则将imm装入PC，实现程序转移；否则PC值加1，即顺序执行。</p>
</div>
<div class="paragraph">
<p>指令存储器是只读存储器，可以使用<a href="mem-memory.html" class="xref page">存储器实验</a>中学习的ROM模块，在初始化时写入要执行的指令编码。运行时只提供读访问，根据输入地址，输出该地址单元存储的指令。
根据<a href="cu-overview.html#bookmark-cu-isa" class="xref page">指令系统</a>设计，一条指令包含5个部分，opcode指定指令功能，连接到控制器的输入；rs1、rs2、rd连接到寄存器堆三个端口的地址；imm作为运算数经多路器连接到ALU的Y输入端，也可以作为转移地址送给PC。</p>
</div>
</div>
<div class="sect2">
<h3 id="_控制器"><a class="anchor" href="#_控制器"></a>控制器</h3>
<div class="paragraph">
<p>控制器以指令opcode作为输入，为数据通路中所有单元产生控制信号。</p>
</div>
<div class="paragraph">
<p><a href="#fig-cu-arch-2">图 1</a>单周期数据通路中，需要产生如下控制信号：</p>
</div>
<div class="ulist">
<ul>
<li>
<p>多路器的选择信号Ysel：为0时，选择将寄存器堆的RD2输出数据送给ALU的Y输入端；为1时，ALU的Y操作数来自指令中的立即数imm。</p>
</li>
<li>
<p>ALU的运算控制信号：根据前面ALU实验的设计，需要产生ALU的M、S0、S1控制信号。</p>
</li>
<li>
<p>寄存器堆的写允许信号RegWr：为1时，当在CLK时钟上升沿到来，寄存器堆执行写入操作。</p>
</li>
<li>
<p>PC装数使能信号LoadPC：为1时，PC装载来自指令中的立即数imm；为0时，PC加1。</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>因为指令系统的简单和规整，控制器的设计就是设计译码器来确定控制信号。对于指令系统中的R型和I型指令，控制器根据opcode的值，译码产生数据通路上的各个控制信号，实现指令功能。对于指令系统中的B型指令，控制器还需要来自ALU产生的标志位，与Opcode的值一起，译码产生控制信号。下面分别分析这两种类型的指令译码。</p>
</div>
<div class="sect3">
<h4 id="_1r型和ｉ型指令的译码"><a class="anchor" href="#_1r型和ｉ型指令的译码"></a>1．R型和Ｉ型指令的译码</h4>
<div class="paragraph">
<p>以“addi rd, rs1, #imm”指令为例，该指令将rs1寄存器的值与立即数imm相加，结果存入rd寄存器。
rs1寄存器的值已经通过寄存器堆的RD1连接到了ALU的X输入端。为了将立即数imm送给ALU的Y输入端，需要使多路器的控制信号Ysel为1。ALUop应控制ALU进行加法运算，如果采用前面实验的ALU电路，控制信号M、S0、S1均为0。为了将运算结果写入寄存器堆，RegWr信号应为1。而LoadPC信号应为0，因为addi不是分支指令，不会产生程序转移。
<a href="#fig-cu-flow-addi">图 2</a>数据通路图直观地反映了上述分析，绿色通路表示有效的信息流，红色表示有效的控制信号。</p>
</div>
<div id="fig-cu-flow-addi" class="imageblock">
<div class="content">
<img src="_images/cu-flow-addi.png" alt="cu flow addi">
</div>
<div class="title">图 2. addi指令的信息流及控制</div>
</div>
<div class="paragraph">
<p>指令译码的真值表如<a href="#tab-cu-opdecode-1">表 1</a>所示。表中只给出了addi指令的控制信号取值，类似地可以分析出其他指令的控制信号取值。有了真值表，就可以进一步得到指令译码器的电路。</p>
</div>
<table id="tab-cu-opdecode-1" class="tableblock frame-all grid-all stretch">
<caption class="title">表 1. R型和Ｉ型指令的译码</caption>
<colgroup>
<col style="width: 14%;">
<col style="width: 14%;">
<col style="width: 9%;">
<col style="width: 9%;">
<col style="width: 9%;">
<col style="width: 9%;">
<col style="width: 9%;">
<col style="width: 9%;">
<col style="width: 9%;">
<col style="width: 9%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">指令助记符</th>
<th class="tableblock halign-left valign-top">opcode</th>
<th class="tableblock halign-left valign-top">RegWr</th>
<th class="tableblock halign-left valign-top">Ysel</th>
<th class="tableblock halign-left valign-top">M</th>
<th class="tableblock halign-left valign-top">S0</th>
<th class="tableblock halign-left valign-top">S1</th>
<th class="tableblock halign-left valign-top">branch</th>
<th class="tableblock halign-left valign-top">brType0</th>
<th class="tableblock halign-left valign-top">brType1</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">add</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">0001</p></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">sub</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">0010</p></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">and</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">0011</p></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">or</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">0100</p></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">xor</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">0101</p></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">addi</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">0110</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">1</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">1</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">0</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">0</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">0</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">0</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">0</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">0</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">andi</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">0111</p></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">ori</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">1000</p></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">xori</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">1001</p></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">beq</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">0110</p></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">bne</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">1011</p></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">blt</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">1100</p></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">bge</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">1101</p></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
</tbody>
</table>
<div class="paragraph">
<p>注：表中2位brType是为下面分支指令预留，运算指令全部填0即可。</p>
</div>
</div>
<div class="sect3">
<h4 id="_2分支指令"><a class="anchor" href="#_2分支指令"></a>2．分支指令</h4>
<div class="paragraph">
<p>以“beq rs1, rs2, #imm”指令为例，该指令比较rs1和rs2寄存器的值是否相等，如果相等，则程序转移，下一条指令的地址由imm给出；如果不相等，则顺序执行。
转移发生时分支指令的信息流如<a href="#fig-cu-flow-branch">图 3</a>所示，绿色通路表示有效的信息流，红色和蓝色表示控制信号。</p>
</div>
<div id="fig-cu-flow-branch" class="imageblock">
<div class="content">
<img src="_images/cu-flow-branch.png" alt="cu flow branch">
</div>
<div class="title">图 3. 转移发生时的分支指令信息流</div>
</div>
<div class="paragraph">
<p>当转移发生时，控制信号LoadPC=1，将转移地址装入PC；如果不发生转移，LoadPC=0，PC加1。
可见，LoadPC并不是固定为1或为0，而是要根据比较运算的结果决定程序是否转移。所以，LoadPC不能单纯根据opcode产生。
opcode只能分辨是不是分支指令以及比较的类型，还需要与比较运算配合，才能产生控制信号。</p>
</div>
<div class="paragraph">
<p><a href="#fig-cu-branch">图 4</a>给出了转移信号的生成方法。
其中EQ、NE、LT、GE是比较的结果，分别表示相等、不等、小于、大于等于，可以采用前面<a href="op-compare.html" class="xref page">比较运算实验</a>的结果。
4选1多路器用来从4种比较结果中选择一个。2位的选择信号brType由指令译码根据分支指令的类型产生。
多路器输出的信号还不能直接作为LoadPC信号，还要判断当前指令是不是转移指令。所以由branch信号控制与门，如果不是分支指令，LoadPC为0；是分支指令，再将多路器的输出作为LoadPC，也就是根据指令类型和比较结果决定程序是否转移。</p>
</div>
<div id="fig-cu-branch" class="imageblock">
<div class="content">
<img src="_images/cu-branch.png" alt="cu branch" width="585">
</div>
<div class="title">图 4. 转移信号的产生</div>
</div>
<div class="paragraph">
<p><a href="#tab-cu-opdecode-2">表 2</a>给出了beq指令的控制信号取值。</p>
</div>
<table id="tab-cu-opdecode-2" class="tableblock frame-all grid-all stretch">
<caption class="title">表 2. 分支指令的译码</caption>
<colgroup>
<col style="width: 14%;">
<col style="width: 14%;">
<col style="width: 9%;">
<col style="width: 9%;">
<col style="width: 9%;">
<col style="width: 9%;">
<col style="width: 9%;">
<col style="width: 9%;">
<col style="width: 9%;">
<col style="width: 9%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">指令助记符</th>
<th class="tableblock halign-left valign-top">opcode</th>
<th class="tableblock halign-left valign-top">RegWr</th>
<th class="tableblock halign-left valign-top">Ysel</th>
<th class="tableblock halign-left valign-top">M</th>
<th class="tableblock halign-left valign-top">S0</th>
<th class="tableblock halign-left valign-top">S1</th>
<th class="tableblock halign-left valign-top">branch</th>
<th class="tableblock halign-left valign-top">brType0</th>
<th class="tableblock halign-left valign-top">brType1</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">beq</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">0110</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">0</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">0</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">1</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">0</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">0</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">1</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">0</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">0</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">bne</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">1011</p></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">blt</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">1100</p></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">bge</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">1101</p></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_实验任务"><a class="anchor" href="#_实验任务"></a>实验任务</h2>
<div class="sectionbody">
<div class="olist arabic">
<ol class="arabic">
<li>
<p>设计控制器</p>
<div class="olist loweralpha">
<ol class="loweralpha" type="a">
<li>
<p>opcode译码</p>
<div class="paragraph">
<p>根据各个指令的功能，设计<a href="#tab-cu-opdecode-1">表 1</a>和<a href="#tab-cu-opdecode-2">表 2</a>的输出取值。使用真值表生成电路图，操作方法见<a href="../ds-generate-circuit.html" class="xref page">电路生成</a>。</p>
</div>
</li>
<li>
<p>分支判断</p>
<div class="paragraph">
<p>根据<a href="#fig-cu-branch">图 4</a>产生转移控制信号LoadPC。</p>
</div>
</li>
</ol>
</div>
</li>
<li>
<p>连接电路</p>
<div class="paragraph">
<p>按照<a href="#fig-cu-arch-2">图 1</a>将各个子电路连接起来，并添加Reset输入引脚和CLK时钟输入引脚。</p>
</div>
<div class="paragraph">
<p>程序计数器PC可使用可预置数的计数器组件，该组件位于菜单项“Components/组件 ➤ Memory/存储器 ➤ Counter with preset / 计数器(可预设)”。</p>
</div>
</li>
<li>
<p>仿真验证</p>
<div class="paragraph">
<p>因为控制器的作用是控制指令的执行，所以需要通过执行指令来检验控制器的设计。<a href="#exa-cu-2">例 1</a>给出了一个测试程序的例子。</p>
</div>
<div id="exa-cu-2" class="exampleblock">
<div class="title">例 1. 分支指令测试程序示例</div>
<div class="content">
<div class="listingblock">
<div class="content">
<pre>0: 0x1815  addi r1, r0, #5
1: 0x202a  ori  r2, r0, #10
2: 0x09b0  sub  r3, r1, r2
3: 0x2ec0  bne  r2, r3, #0</pre>
</div>
</div>
</div>
</div>
<div class="paragraph">
<p>上面测试程序使用的指令种类有限，自己编写程序进行更全面的验证。</p>
</div>
</li>
<li>
<p>运行斐波那契数列计算程序</p>
<div class="olist loweralpha">
<ol class="loweralpha" type="a">
<li>
<p>将概述中<a href="cu-overview.html#exa-cu-isa" class="xref page">斐波那契数列计算程序</a>的机器码作为ROM的数据。</p>
</li>
<li>
<p>仿真运行程序，验证结果是否正确。</p>
</li>
</ol>
</div>
</li>
<li>
<p>实验结果分析</p>
<div class="paragraph">
<p>对仿真结果进行分析。</p>
</div>
</li>
</ol>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_思考与拓展"><a class="anchor" href="#_思考与拓展"></a>思考与拓展</h2>
<div class="sectionbody">
<div class="paragraph">
<p>本实验的转移指令的目的地址是由立即数给出的，即直接寻址。如果改为相对寻址，即目的地址=(PC)+imm，数据通路应做何种变化？</p>
</div>
<div class="sidebarblock text-center">
<div class="content">
<div class="title">许可 | License</div>
<div class="paragraph">
<p><a href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh">CC BY-NC-SA：署名-非商业性使用-相同方式共享 4.0 国际许可协议</a></p>
</div>
<div class="paragraph">
<p>作者：
肖铁军 &lt;<a href="mailto:xiaotiejun@foxmail.com.cn">xiaotiejun@foxmail.com.cn</a>&gt;</p>
</div>
</div>
</div>
</div>
</div>
</article>
  </div>
</main>
</div>
<footer class="footer">
  <p>This page was built using the Antora default UI.</p>
  <p>The source code for this UI is licensed under the terms of the MPL-2.0 license.</p>
</footer>
<script id="site-script" src="../../../_/js/site.js" data-ui-root-path="../../../_"></script>
<script async src="../../../_/js/vendor/highlight.js"></script>
  </body>
</html>
